<?php


use Ramsey\Uuid\Uuid;
use Random\RandomException;

function code(int $length = 6): string
{
    try {
        return str_pad(random_int(1, pow(10, $length) - 1), $length, 0, STR_PAD_LEFT);
    } catch (RandomException $e) {
        abort(403, '生成随机数失败: ' . $e->getMessage());
    }
}

function uuid(): string
{
    return Uuid::uuid4()->getHex();
}
